/*
  学习目标：受控组件-常见的表单元素
  1. state控制表单元素的value或者checked
  2. onChange配合setState修改状态
*/

import React, { Component } from 'react';

export default class App extends Component {
  // 1. 声明state，name
  state = {
    name: 'zs',
    intro: '狂徒',
    city: '3',
    isSingle: true,
  };

  // 2. 通过this.state.name 赋值给input的value属性

  handleChangeName = (e) => {
    // sst
    this.setState({ name: e.target.value });
  };

  handleChangeIntro = (e) => {
    this.setState({ intro: e.target.value });
  };

  handleChangeCity = (e) => {
    this.setState({ city: e.target.value });
  };

  handleChangeSingle = (e) => {
    this.setState({ isSingle: e.target.checked });
  };
  // 3. 监听onChange事件， 修改state
  render() {
    const { name, intro, city, isSingle } = this.state;
    return (
      <div>
        姓名：
        <input value={name} type="text" onChange={this.handleChangeName} />
        <br />
        描述：<textarea value={intro} onChange={this.handleChangeIntro}></textarea>
        <br />
        城市：
        <select value={city} onChange={this.handleChangeCity}>
          <option value="1">北京</option>
          <option value="2">上海</option>
          <option value="3">广州</option>
          <option value="4">深圳</option>
        </select>
        <br />
        是否单身：
        <input checked={isSingle} onChange={this.handleChangeSingle} type="checkbox" />
      </div>
    );
  }
}
